

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>argoverse.utils.ffmpeg_utils &mdash; argoverse  documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
        <script type="text/javascript" src="../../../_static/jquery.js"></script>
        <script type="text/javascript" src="../../../_static/underscore.js"></script>
        <script type="text/javascript" src="../../../_static/doctools.js"></script>
        <script type="text/javascript" src="../../../_static/language_data.js"></script>
    
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/graphviz.css" type="text/css" />
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../../index.html" class="icon icon-home"> argoverse
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <!-- Local TOC -->
              <div class="local-toc"></div>
            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../index.html">argoverse</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../../index.html">Module code</a> &raquo;</li>
        
      <li>argoverse.utils.ffmpeg_utils</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for argoverse.utils.ffmpeg_utils</h1><div class="highlight"><pre>
<span></span><span class="c1"># &lt;Copyright 2019, Argo AI, LLC. Released under the MIT license.&gt;</span>


<span class="kn">from</span> <span class="nn">argoverse.utils.subprocess_utils</span> <span class="k">import</span> <span class="n">run_command</span>


<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Create a high-quality video using the encoder x264.</span>
<span class="sd">For x264, the valid Constant Rate Factor (crf) range is 0-51.</span>

<span class="sd">The range of the quantizer scale is 0-51: where 0 is lossless,</span>
<span class="sd">23 is default, and 51 is worst possible. A lower value is a</span>
<span class="sd">higher quality and a subjectively sane range is 18-28. Consider 18 to be</span>
<span class="sd">visually lossless or nearly so: it should look the same or nearly the</span>
<span class="sd">same as the input but it isn&#39;t technically lossless.</span>
<span class="sd">&quot;&quot;&quot;</span>


<div class="viewcode-block" id="write_video"><a class="viewcode-back" href="../../../argoverse.utils.html#argoverse.utils.ffmpeg_utils.write_video">[docs]</a><span class="k">def</span> <span class="nf">write_video</span><span class="p">(</span><span class="n">image_prefix</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">output_prefix</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">fps</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">10</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Use FFMPEG to write a video to disk, from a sequence of images.</span>

<span class="sd">    Args:</span>
<span class="sd">        image_prefix: string, with %d embedded inside and ending with</span>
<span class="sd">            a prefix, e.g. .png/.jpg. Absolute path</span>
<span class="sd">        output_prefix: absolute path for output video, without .mp4 prefix</span>
<span class="sd">        fps: integer, frames per second</span>

<span class="sd">    Returns:</span>
<span class="sd">        None</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">cmd</span> <span class="o">=</span> <span class="n">f</span><span class="s2">&quot;ffmpeg -r </span><span class="si">{fps}</span><span class="s2"> -i </span><span class="si">{image_prefix}</span><span class="s2"> -vcodec libx264 -profile:v main&quot;</span>
    <span class="n">cmd</span> <span class="o">+=</span> <span class="s2">&quot; -level 3.1 -preset medium -crf 23 -x264-params ref=4 -acodec&quot;</span>
    <span class="n">cmd</span> <span class="o">+=</span> <span class="n">f</span><span class="s2">&quot; copy -movflags +faststart -pix_fmt yuv420p  -vf scale=920:-2 </span><span class="si">{output_prefix}</span><span class="s2">_</span><span class="si">{fps}</span><span class="s2">fps.mp4&quot;</span>
    <span class="nb">print</span><span class="p">(</span><span class="n">cmd</span><span class="p">)</span>
    <span class="n">run_command</span><span class="p">(</span><span class="n">cmd</span><span class="p">)</span></div>


<div class="viewcode-block" id="write_nonsequential_idx_video"><a class="viewcode-back" href="../../../argoverse.utils.html#argoverse.utils.ffmpeg_utils.write_nonsequential_idx_video">[docs]</a><span class="k">def</span> <span class="nf">write_nonsequential_idx_video</span><span class="p">(</span><span class="n">img_wildcard</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">output_fpath</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">fps</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Args:</span>
<span class="sd">        img_wildcard: string</span>
<span class="sd">        output_fpath: string</span>
<span class="sd">        fps: integer, frames per second</span>

<span class="sd">    Returns:</span>
<span class="sd">       None</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">cmd</span> <span class="o">=</span> <span class="n">f</span><span class="s2">&quot;ffmpeg -r </span><span class="si">{fps}</span><span class="s2"> -f image2 -i </span><span class="si">{img_wildcard}</span><span class="s2">&quot;</span>
    <span class="n">cmd</span> <span class="o">+=</span> <span class="s2">&quot; -vcodec libx264 -profile:v main&quot;</span>
    <span class="n">cmd</span> <span class="o">+=</span> <span class="s2">&quot; -level 3.1 -preset medium -crf 23 -x264-params ref=4 -acodec&quot;</span>
    <span class="n">cmd</span> <span class="o">+=</span> <span class="n">f</span><span class="s2">&quot; copy -movflags +faststart -pix_fmt yuv420p  -vf scale=920:-2&quot;</span>
    <span class="n">cmd</span> <span class="o">+=</span> <span class="n">f</span><span class="s2">&quot; </span><span class="si">{output_fpath}</span><span class="s2">&quot;</span>
    <span class="nb">print</span><span class="p">(</span><span class="n">cmd</span><span class="p">)</span>
    <span class="n">run_command</span><span class="p">(</span><span class="n">cmd</span><span class="p">)</span></div>
</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2019, Argo AI, LLC

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>